package com.loft.model.innerface;

import java.util.List;

import com.loft.comm.util.LogCenter;
import com.loft.vo.Vo;

import android.graphics.Bitmap;
import android.util.Log;

/**
 * @InterfaceName: ConnectionInterface.java
 * @Description:策略工厂，维持一个对ConAndGetInfo的引用
 * @Author: hebin
 * @CreateDate: 2011/12/12
 */
public class HTTPServiceController {
	private HTTPService _connection;
	private final String Tag = this.getClass().getName();

	// 采用反射的方式生成指定类
	public HTTPServiceController(String className) {
		try {
			Class<?> conAndReader = Class.forName(className);
			this._connection = (HTTPService) conAndReader.getConstructor()
					.newInstance();
		} catch (Exception e) {
			LogCenter.getInstance().error(Tag, e.toString());
			this._connection = null;
		}

	}

	// 采用反射的方式生成指定类
	public HTTPServiceController(String className, String uid) {
		try {
			Class<?> conAndReader = Class.forName(className);
			this._connection = (HTTPService) conAndReader.getConstructor(
					String.class).newInstance(uid);
		} catch (Exception e) {
			LogCenter.getInstance().error(Tag, e.toString());
			this._connection = null;
		}

	}

	// 采用反射的方式生成指定类
	public HTTPServiceController(String className, int page, int pageSize) {
		try {
			Class<?> conAndReader = Class.forName(className);
			this._connection = (HTTPService) conAndReader.getConstructor(
					Integer.class, Integer.class).newInstance(page, pageSize);
		} catch (Exception e) {
			Log.e("error", e.toString());
			this._connection = null;
		}

	}

//	// 采用反射的方式生成指定类
//	public HTTPServiceController(String className, List<String> urlList) {
//		try {
//			Class<?> conAndReader = Class.forName(className);
//			this._connection = (HTTPService) conAndReader.getConstructor(
//					List.class).newInstance(urlList);
//		} catch (Exception e) {
//			LogCenter.getInstance().error(Tag, e.toString());
//			this._connection = null;
//		}
//
//	}

	public List<? extends Vo> doConnect() {
		if (_connection == null) {
			return null;
		}
		return _connection.parseJsonData(_connection
				.connectionAndGetJsonString());
	}

	public List<Bitmap> doBitmapDownload() {
		if (_connection == null) {
			return null;
		}
		return ((BitmapDownloader) _connection).download();
	}
}
